package com.celan.year2022.day1218;

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[][] m = new int[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    m[i][j] = in.nextInt();
                }
            }
            int k = in.nextInt();
            int res = calculate(m, k - 1);
            System.out.println(res);
        }
    }

    private static int calculate(int[][] m, int idx) {
        boolean flag = false;
        for (int i = 0; i < m[0].length; i++) {
            if (i == idx) continue;
            if (m[idx][i] == 0) {
                flag = true;
            } else {
                flag = false;
                break;
            }
        }
        if (flag) {
            return m[idx][idx];
        }

        int time = 0;
        int self = m[idx][idx];
        time += self;
        int max = 0;
        for (int j = 0; j < m[0].length; j++) {
            if (j == idx) continue;
            if (m[idx][j] == 0) continue;
            if (m[idx][j] == 1) {
                max=Math.max(max,calculate(m, j));
            }
        }
        time += max;
        return time;
    }


}
